package com.tools.commons.utils;

import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * @author wangminggen
 */
public class StringUtils {
    private static final Logger log = getLogger(StringUtils.class);

    private StringUtils() {
    }

    public static final String EMPTY = "";
    public static final String SPACE = " ";
    public static final String LF = "\n";
    public static final String CR = "\r";

    public static String underlineToCamelCase(String underLineStr, boolean firstWordUpper) {
        StringBuilder sb = new StringBuilder();
        if (underLineStr != null && underLineStr.trim().length() > 0) {
            boolean nextUpper = firstWordUpper;
            for (int i = 0; i < underLineStr.length(); i++) {
                char ch = underLineStr.charAt(i);
                if ('_' == ch) {
                    nextUpper = true;
                    continue;
                }
                if (nextUpper) {
                    ch = Character.toUpperCase(ch);
                    nextUpper = false;
                }
                sb.append(ch);
            }
        }
        return sb.toString();
    }

    public static String camelCaseToUnderLine(String camelCaseStr) {
        StringBuilder sb = new StringBuilder();
        if (camelCaseStr != null && camelCaseStr.trim().length() > 0) {
            for (int i = 0; i < camelCaseStr.length(); i++) {
                char ch = camelCaseStr.charAt(i);
                if (ch >= 'A' && ch <= 'Z') {
                    sb.append("_");
                    ch = Character.toLowerCase(ch);
                }
                sb.append(ch);
            }
        }
        return sb.toString();
    }

    public static boolean isNotEmpty(CharSequence string) {
        return org.apache.commons.lang3.StringUtils.isNotEmpty(string);
    }

    public static boolean isEmpty(CharSequence string) {
        return org.apache.commons.lang3.StringUtils.isEmpty(string);
    }

    public static boolean isBlank(CharSequence string) {
        return org.apache.commons.lang3.StringUtils.isBlank(string);
    }

    public static boolean isNotBlank(CharSequence string) {
        return org.apache.commons.lang3.StringUtils.isNotBlank(string);
    }

    public static boolean isNumeric(CharSequence string) {
        return org.apache.commons.lang3.StringUtils.isNumeric(string);
    }

    public static boolean equals(CharSequence cs1, CharSequence cs2) {
        return org.apache.commons.lang3.StringUtils.equals(cs1, cs2);
    }

    public static boolean equalsIgnoreCase(CharSequence cs1, CharSequence cs2) {
        return org.apache.commons.lang3.StringUtils.equalsIgnoreCase(cs1, cs2);
    }
}
